
const ctxPath = document.getElementById("ctxPath").value;
Vue.config.productionTip = false
import batchUtil from "../util/batchUtil.js"

new Vue({
    el: '#app',
    components: {
        batchUtil
    },
    data() {
        return {
            urlList: ctxPath+'/EInterfaceIsup/list',
            baseurlList: ctxPath+'/EInterfaceMap/comtreelist',
            left: 'left',
            total: 0,
            opcOptions:[],
            listData: [],
            currentPage: 1,
            pageSize: 10,
            loading:false,
            multipleSelection:[],
            form: {
                startTime: '',
                endTime: '',
                vcCallingNumber:'',
                vcCalledNumber:'',
                intDpc: '',
                intOpc: ''
            },
            addOrUpdateDialogVisible: false,
            add_or_update_flag: true,
            addOrUpdateDialogTitle: '',
            showDgId: '',
            addForm:{},
            quertTypeOptions:[],
            uploadFileDialogVisible: false,
            uploadFileName: '',
            uploadFormData: "",
        }
    },
    created() {
        this.myInit();
    },
    methods: {
        resetForm() {
            this.form.startTime = "";
            this.form.endTime = "";
            this.form.vcCallingNumber = "";
            this.form.vcCalledNumber = "";
            this.form.intDpc = "";
            this.form.intOpc = "";
        },
        headStyle() {
            return "font-family: Microsoft YaHei, Microsoft YaHei;\n" +
                "font-weight: blod;\n" +
                "font-size: 14px;\n" +
                "color: #333333;\n" +
                "line-height: 0px;\n" +
                "text-align: center;\n" +
                "font-style: normal;\n" +
                "text-transform: none;background-color:#F6F7FB;"
        },
        rowStyle({row, column, rowIndex, columnIndex}) {
            if (rowIndex % 2 === 0) {
                return "text-align:center;" +
                    "font-family: Microsoft YaHei, Microsoft YaHei;\n" +
                    "font-weight: 400;\n" +
                    "font-size: 14px;\n" +
                    "color: #666666;\n" +
                    "line-height: 0px;\n" +
                    "font-style: normal;\n" +
                    "text-transform: none;"

            } else {
                return "text-align:center;" +
                    "font-family: Microsoft YaHei, Microsoft YaHei;\n" +
                    "font-weight: 400;\n" +
                    "font-size: 14px;\n" +
                    "color: #666666;\n" +
                    "line-height: 0px;\n" +
                    "font-style: normal;\n" +
                    "text-transform: none;background-color:#F6F7FB;"
            }
        },
        getDateByType(type) {
            var date = new Date();
            var myyear = date.getFullYear();
            var mymonth = date.getMonth() + 1;
            var myweekday = date.getDate();
            if (mymonth < 10) {
                mymonth = '0' + mymonth;
            }
            if (myweekday < 10) {
                myweekday = '0' + myweekday;
            }
            if (type === "year") {
                return myyear;
            } else if (type === "month") {
                return myyear + '-' + mymonth;
            }
            return myyear + '-' + mymonth + '-' + myweekday;
        },
        // 编写日期格式化方法
        dateFormat: function(row, column) {
            const date = row[column.property]
            if (date === undefined) {
                return ''
            }
            // 这里的格式根据需求修改
            return moment(date).format('YYYY-MM-DD HH:mm:ss.SSS')
        },
        myInit() {
            let me = this;
            this.form.startTime = this.getDateByType() + " 00:00:00";
            this.form.endTime = this.getDateByType() + " 23:59:59";
            $.ajax({
                type:"get",
                url:this.baseurlList,
                dataType:'json',
                success : function(data) {
                    var objs = eval(data);
                    console.log(objs);
                    me.opcOptions = data.data;
                },
                error: function (data) {
                    console.info("error: " + data.responseText);
                }
            });
            this.queryData();
        },
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },
        queryData(){
            let me = this;
            me.loading = true;
            let postData = {
                iDisplayStart: me.currentPage,
                iDisplayLength: me.pageSize,
                sSortDir: "desc",
                sSortCol: "DtsTime",
                DtsTime: me.form.startTime,
                DteTime: me.form.endTime,
                vcCallingNumber: me.form.vcCallingNumber,
                intOpc: me.form.intOpc,
                intDpc: me.form.intDpc,
                vcCalledNumber: me.form.vcCalledNumber
            };
            $.ajax({
                type: "post",
                url: this.urlList,
                data:postData,
                dataType: "json",
                complete: function (data) {
                    data = data.responseJSON;
                    if(data.code === 200) {
                        me.listData = data.data.aData;
                        me.total = data.data.iTotalRecords;
                        me.currentPage = 1;
                        me.pageSize = 10;
                    }else {
                        me.$message({
                            message: data.message,
                            type: 'info',
                            duration: 1000,
                            showClose: true
                        });
                    }
                    me.loading = false;
                },
                error: function (data) {
                    me.$message({
                        message: '查询失败',
                        type: 'error',
                        duration: 1000,
                        showClose: true
                    });
                    me.loading = false;
                }
            });
        },
        QueryDataRef(){
            let me = this;
            me.loading = true;
            let postData = {
                iDisplayStart: me.currentPage,
                iDisplayLength: me.pageSize,
                sSortDir: "desc",
                sSortCol: "DtsTime",
                DtsTime: me.form.startTime,
                vcCallingNumber: me.form.vcCallingNumber,
                intOpc: me.form.intOpc,
                intDpc: me.form.intDpc,
                vcCalledNumber: me.form.vcCalledNumber,
                DteTime: me.form.endTime
            };
            $.ajax({
                type: "post",
                url:this.urlList,
                data:postData,
                dataType: "json",
                complete: function (data) {
                    data = data.responseJSON;
                    if(data.code === 200) {
                        me.listData = data.data.aData;
                    }else {
                        me.$message({
                            message: data.message,
                            type: 'info',
                            duration: 1000,
                            showClose: true
                        });
                    }
                    me.loading = false;
                },
                error: function (data) {
                    me.$message({
                        message: '查询失败',
                        type: 'error',
                        duration: 1000,
                        showClose: true
                    });
                    me.loading = false;
                }
            });
        },
        handleSizeChange(val) {
            this.pageSize = val;
            this.currentPage = 1;
            let me = this;
            me.loading = true;
            let postData = {
                iDisplayStart: val,
                iDisplayLength: me.pageSize,
                sSortDir: "desc",
                sSortCol: "DtsTime",
                DtsTime: me.form.startTime,
                vcCallingNumber: me.form.vcCallingNumber,
                intOpc: me.form.intOpc,
                intDpc: me.form.intDpc,
                vcCalledNumber: me.form.vcCalledNumber,
                DteTime: me.form.endTime
            };
            $.ajax({
                type: "post",
                url:this.urlList,
                dataType: "json",
                data:postData,
                complete: function (data) {
                    data = data.responseJSON;
                    if(data.code === 200) {
                        me.listData = data.data.aData;
                    }else {
                        me.$message({
                            message: data.message,
                            type: 'info',
                            duration: 1000,
                            showClose: true
                        });
                    }
                    me.loading = false;
                },
                error: function (data) {
                    me.$message({
                        message: '查询失败',
                        type: 'error',
                        duration: 1000,
                        showClose: true
                    });
                    me.loading = false;
                }
            });
        },
        handleCurrentChange(val) {
            this.currentPage = val;
            val = this.pageSize * val - 1;
            let me = this;
            me.loading = true;
            let postData = {
                iDisplayStart: val,
                iDisplayLength: me.pageSize,
                sSortDir: "desc",
                sSortCol: "DtsTime",
                DtsTime: me.form.startTime,
                vcCallingNumber: me.form.vcCallingNumber,
                intOpc: me.form.intOpc,
                intDpc: me.form.intDpc,
                vcCalledNumber: me.form.vcCalledNumber,
                DteTime: me.form.endTime
            };
            $.ajax({
                type: "post",
                url:this.urlList,
                dataType: "json",
                data:postData,
                complete: function (data) {
                    data = data.responseJSON;
                    if(data.code === 200) {
                        me.listData = data.data.aData;
                    }else {
                        me.$message({
                            message: data.message,
                            type: 'info',
                            duration: 1000,
                            showClose: true
                        });
                    }
                    me.loading = false;
                },
                error: function (data) {
                    me.$message({
                        message: '查询失败',
                        type: 'error',
                        duration: 1000,
                        showClose: true
                    });
                    me.loading = false;
                }
            });
        },
        typeIndex(index) {
            return (this.currentPage - 1) * this.pageSize + index + 1;
        },
        exportData() {
            window.open(ctxPath + "/EInterfaceIsup/exportData?DtsTime=" + this.form.startTime+"&DteTime=" + this.form.endTime+"&vcCallingNumber=" + this.form.vcCallingNumber+"&vcCalledNumber=" + this.form.vcCalledNumber+"&intOpc=" + this.form.intOpc+"&intDpc=" + this.form.intDpc);
        },
    }
});